home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Add-Ons / MPW / MPW re2c 1.1 / examples / rexx / scanio.c < prev   
Encoding:
Text File  |  1995-06-01  |  1.2 KB  |  42 lines  |  [TEXT/KAHL]

  1. uchar *ScanFill(uchar *cursor){
  2.     unsigned cnt = s->tok - s->bot;
  3.     s->pos += cursor - s->mrk;
  4.     if(cnt){
  5.         if(s->eot){
  6.             unsigned len = s->eot - s->tok;
  7.             memcpy(s->bot, s->tok, len);
  8.             s->eot = &s->bot[len];
  9.             if((len = s->lim - cursor) != 0)
  10.                 memcpy(s->eot, cursor, len);
  11.             cursor = s->eot;
  12.             s->lim = &cursor[len];
  13.         } else {
  14.             memcpy(s->bot, s->tok, s->lim - s->tok);
  15.             cursor -= cnt;
  16.             s->lim -= cnt;
  17.         }
  18.         s->tok = s->bot;
  19.         s->ptr -= cnt;
  20.     }
  21.     if((s->top - s->lim) < 512){
  22.         uchar *buf = (uchar*) malloc(((s->lim - s->bot) + 512)*sizeof(uchar));
  23.         memcpy(buf, s->bot, s->lim - s->bot);
  24.         s->tok = buf;
  25.         s->ptr = &buf[s->ptr - s->bot];
  26.         if(s->eot)
  27.             s->eot = &buf[s->eot - s->bot];
  28.         cursor = &buf[cursor - s->bot];
  29.         s->lim = &buf[s->lim - s->bot];
  30.         s->top = &s->lim[512];
  31.         free(s->bot);
  32.         s->bot = buf;
  33.     }
  34.     s->mrk = cursor;
  35.     if(ScanCBIO.file){
  36.         if((cnt = read(ScanCBIO.u.f.fd, (char*) s->lim, 512)) != 512)
  37.             memset(&s->lim[cnt], 0, 512 - cnt);
  38.         s->lim += 512;
  39.     }
  40.     return cursor;
  41. }
  42.